package com.sskj.cndragon.ui.activity;


import com.lzy.okgo.model.Response;
import com.sskj.cndragon.bean.PayWayBean;
import com.sskj.cndragon.http.HttpConfig;
import com.sskj.cndragon.presenter.BasePresenter;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;

import java.util.zip.DataFormatException;

/**
 * @author Hey
 * Create at  2019/05/24
 */
class ReceiptPresenter extends BasePresenter<ReceiptActivity> {

    public void getPayWay() {
        httpService.getPayWay(SPUtil.get(SPConfig.ID, ""))
                .tag(this)
                .execute(new JsonCallBack<HttpData<PayWayBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<PayWayBean>> response) {
                        HttpData<PayWayBean> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.getPayWayOK(body.getData());
                        } else {
                            ToastUtil.showShort(body.getMsg());
                        }

                    }
                });
    }

    public void changeLock(String type, String status) {
        httpService.changeLock(SPUtil.get(Constans.ID, ""), type, status)
                .tag(this)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtil.showShort(body.getMsg());
                        if (body.getStatus() == HttpConfig.OK) {
                            getPayWay();
                        }
                    }
                });
    }
}
